package com.taofuxn.yycreazy.ui.activity;

import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.taofuxn.yycreazy.R;
import com.taofuxn.yycreazy.mvp.BasePresenter;
import com.taofuxn.yycreazy.ui.base.MvpToobarActivity;
import com.taofuxn.yycreazy.ui.view.XCFlowLayout;

import butterknife.InjectView;

/**
 * 搜索页面
 * Created by taofuxn on 2016/9/23.
 */
public class SearchActivity extends MvpToobarActivity {

    @InjectView(R.id.xcflayout)
    XCFlowLayout xcflayout;
    @InjectView(R.id.edtSearchKey)
    EditText edtSearchKey;

    String ci[] = new String[]{"开始装逼", "淫荡", "老司机", "小学生", "管理员","咸鱼"};
    String key = "";

    @Override
    protected BasePresenter createDefaultPresenter() {
        return null;
    }

    @Override
    protected int setContentLayout() {
        return R.layout.activity_search;
    }

    @Override
    protected void init() {
        setUsedTag(ci);
    }


    private void setUsedTag(String[] ci) {
        ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.leftMargin = 10;
        lp.rightMargin = 10;
        lp.bottomMargin = 10;
        lp.topMargin = 10;
        for (String str : ci) {
            final TextView tv = new TextView(this);
            tv.setText(str);
            tv.setBackgroundDrawable(getResources().getDrawable(R.drawable.tv_select_bg));
            tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    edtSearchKey.setText(tv.getText().toString());
                }
            });
            xcflayout.addView(tv, lp);
        }
    }

    public void finish(String key) {
        Intent intent = new Intent();
        intent.putExtra("key", key);
        setResult(0x001, intent);
        finish();
    }

    @Override
    protected void todoBeforeFinish() {
        key = edtSearchKey.getText().toString();
        finish(key);
    }
}
